package com.runvp.rest.biz;

import com.runvp.common.annotation.Log;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.core.page.TableDataInfo;
import com.runvp.common.enums.BusinessType;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.service.convert.BizRPIConvert;
import com.runvp.service.biz.domain.BizRechargePackageItem;
import com.runvp.service.biz.service.IBizRechargePackageItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充值套餐选项Controller
 *
 * @author runvp
 * @date 2022-09-18
 */
@Controller
@RequestMapping("/biz/rechargePackageItem")
public class BizRechargePackageItemController extends BaseController {
    private String prefix = "biz/rechargePackageItem";

    @Autowired
    private BizRPIConvert bizRPIConvert;
    @Autowired
    private IBizRechargePackageItemService bizRechargePackageItemService;

    @RequiresPermissions("biz:rechargePackageItem:view")
    @GetMapping()
    public String rechargePackageItem(ModelMap mmap, Long showId) {
        mmap.put("showId", showId);
        return prefix + "/rechargePackageItem";
    }

    /**
     * 查询充值套餐选项列表
     */
    @RequiresPermissions("biz:rechargePackageItem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizRechargePackageItem bizRechargePackageItem) {
        startPage();
        List<BizRechargePackageItem> list = bizRechargePackageItemService.selectBizRechargePackageItemList(bizRechargePackageItem);
        return getDataTable(list);
    }

    /**
     * 导出充值套餐选项列表
     */
    @RequiresPermissions("biz:rechargePackageItem:export")
    @Log(title = "充值套餐选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizRechargePackageItem bizRechargePackageItem) {
        List<BizRechargePackageItem> list = bizRechargePackageItemService.selectBizRechargePackageItemList(bizRechargePackageItem);
        ExcelUtil<BizRechargePackageItem> util = new ExcelUtil<>(BizRechargePackageItem.class);
        return util.exportExcel(list, "充值套餐选项数据");
    }

    /**
     * 新增充值套餐选项
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存充值套餐选项
     */
    @RequiresPermissions("biz:rechargePackageItem:add")
    @Log(title = "充值套餐选项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizRechargePackageItem bizRechargePackageItem) {
        return toAjax(bizRechargePackageItemService.insertBizRechargePackageItem(bizRechargePackageItem));
    }

    /**
     * 修改充值套餐选项
     */
    @RequiresPermissions("biz:rechargePackageItem:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizRechargePackageItem bizRechargePackageItem = bizRechargePackageItemService.selectBizRechargePackageItemById(id);
        mmap.put("bizRechargePackageItem", bizRechargePackageItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存充值套餐选项
     */
    @RequiresPermissions("biz:rechargePackageItem:edit")
    @Log(title = "充值套餐选项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizRechargePackageItem bizRechargePackageItem) {
        return toAjax(bizRechargePackageItemService.updateBizRechargePackageItem(bizRechargePackageItem));
    }

    /**
     * 删除充值套餐选项
     */
    @RequiresPermissions("biz:rechargePackageItem:remove")
    @Log(title = "充值套餐选项", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizRechargePackageItemService.deleteBizRechargePackageItemByIds(ids));
    }
}
